const path = require('path');
const fs = require('fs');
const { replyList } = require('./raw-data');

console.log('replyList===', replyList);

let scratchReplys = [];
let logicReplys = [];

for (const reply of replyList) {
  let keyword = reply['rule_name'];
  for (const replyInfo of reply.reply_list_info) {
    if (
      replyInfo.type !== 'news' ||
      !replyInfo.news_info ||
      !replyInfo.news_info.list
    ) {
      console.log('keyword', keyword);
      continue;
    }
    for (const article of replyInfo.news_info.list) {
      if (keyword.indexOf('Scratch') > -1) {
        scratchReplys.push({
          keyword,
          tags: ['scratch'],
          type: 'news',
          title: article.title,
          description: article.digest,
          coverUrl: article.cover_url,
          articleUrl: article.content_url,
        });
      } else {
        logicReplys.push({
          keyword,
          tags: ['logic'],
          type: 'news',
          title: article.title,
          description: article.digest,
          coverUrl: article.cover_url,
          articleUrl: article.content_url,
        });
      }
    }
  }
}

fs.writeFileSync(
  path.resolve(__dirname, 'scratchReplys.json'),
  JSON.stringify(scratchReplys)
);

fs.writeFileSync(
  path.resolve(__dirname, 'logicReplys.json'),
  JSON.stringify(logicReplys)
);
